<?php
class Room extends CI_Model {
	function __construct()
	{
		parent::__construct();
		$this->load->database();
	}
	public function save($data) {
	   $this->db->set($data);
	   if(!$this->db->insert('room')) return false;
	   return $this->db->insert_id();
	}
	public function update($id, $data) {
	   $this->db->where('id', $id);
	   if(!$this->db->update('room', $data)) return false;
	   return true;
	}
	public function delete($id) {
	   $this->db->where('id', $id);
	   if(!$this->db->delete('room')) return false;
	   return true;
	}

	public function getRooms($limit, $start) {
	 	$this->db->select('room.*, city.name as city');
		$this->db->join('city', 'room.city_id=city.id');
        $this->db->limit($limit, $start);

        $query = $this->db->get('room');
		
		return $query->result();
	}
	public function record_count() {
        return $this->db->count_all("room");
    }

	public function getRoomByID($id) {
		
		$this->db->select('room.*, city.name as city_name, city.country_id as country_id');
		$this->db->join('city', 'room.city_id=city.id');
		$this->db->where('room.id', $id);
		$query = $this->db->get('room');
		if ( $query->num_rows > 0 ) {
         // person has account with us
        return $query->row();
      } 
	  return false;
	}

	public function getRoomsByCategory($id) {
		
		$this->db->select('room.*, city.name as city_name');
		$this->db->join('room_category', 'room.id=room_category.room_id');
		$this->db->join('city', 'city.id=room.city_id');
		$this->db->where('room_category.category_id', $id);
		$this->db->order_by('room.name');
		$query = $this->db->get('room');
		return $query->result_array();	
	}

	public function getRoomList(){
		$this->db->select('room.*, room_category.name as category_name');
		$this->db->join('room_category', 'room_category.id=room.category_id');
		$this->db->order_by('room_category.name');
        $query = $this->db->get('room');

        return $query->result_array();
    }

    public function getRoomMetaByID($id) {

        $this->db->select('id, meta_description, meta_title, meta_keyword, url');
        $this->db->where('id', $id);
        $query = $this->db->get('room');


        if ( $query->num_rows > 0 ) {
            // person has account with us
            return $query->row();
        }
        return false;
    }

    public function updateMeta($id, $data) {
        $this->db->where('id', $id);
        if(!$this->db->update('room', $data)) return false;
        return true;
    }
}
?>